home *** CD-ROM | disk | FTP | other *** search
/ Visual Cafe 3 / Visual Cafe 3.ISO / Vcafe / JFC.bin / BorderFactory.java < prev    next >
Text File  |  1998-06-30  |  6KB  |  178 lines

  1. /*
  2.  * @(#)BorderFactory.java    1.9 98/01/30
  3.  *
  4.  * Copyright (c) 1997 Sun Microsystems, Inc. All Rights Reserved.
  5.  *
  6.  * This software is the confidential and proprietary information of Sun
  7.  * Microsystems, Inc. ("Confidential Information").  You shall not
  8.  * disclose such Confidential Information and shall use it only in
  9.  * accordance with the terms of the license agreement you entered into
  10.  * with Sun.
  11.  *
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
  13.  * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  14.  * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  15.  * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
  16.  * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
  17.  * THIS SOFTWARE OR ITS DERIVATIVES.
  18.  *
  19.  */
  20. package com.sun.java.swing;
  21.  
  22. import java.awt.Color;
  23. import java.awt.Font;
  24. import com.sun.java.swing.JComponent;
  25. import com.sun.java.swing.border.*;
  26.  
  27. /**
  28.  * Factory class for vending standard Border objects.  Whereever
  29.  * possible, this factory will hand out references to shared
  30.  * Border instances.
  31.  *
  32.  * @version 1.9 01/30/98
  33.  * @author David Kloba
  34.  */
  35. public class BorderFactory 
  36. {
  37.  
  38.     /** Don't let anyone instantiate this class */
  39.     private BorderFactory() {
  40.     }
  41.  
  42.  
  43. //// LineBorder ///////////////////////////////////////////////////////////////
  44.     public static Border createLineBorder(Color color) {
  45.         return new LineBorder(color, 1);
  46.     }
  47.  
  48.     public static Border createLineBorder(Color color, int thickness)  {
  49.         return new LineBorder(color, thickness);
  50.     }
  51.     
  52. //    public static Border createLineBorder(Color color, int thickness, 
  53. //                    boolean drawRounded)  {
  54. //        return new JLineBorder(color, thickness, drawRounded);
  55. //    }
  56.  
  57. //// BevelBorder /////////////////////////////////////////////////////////////
  58. ///////////////////////////////////////////////////////////////////////////////
  59.     static final Border sharedRaisedBevel = new BevelBorder(BevelBorder.RAISED);
  60.     static final Border sharedLoweredBevel = new BevelBorder(BevelBorder.LOWERED);
  61.  
  62.     public static Border createRaisedBevelBorder() {
  63.         return createSharedBevel(BevelBorder.RAISED);
  64.     }
  65.  
  66.     public static Border createLoweredBevelBorder() {
  67.         return createSharedBevel(BevelBorder.LOWERED);
  68.     }
  69.  
  70.     public static Border createBevelBorder(int type) {
  71.     return createSharedBevel(type);
  72.     }
  73.     
  74.     public static Border createBevelBorder(int type, Color highlight, Color shadow) {
  75.         return new BevelBorder(type, highlight.darker(), highlight, 
  76.                     shadow, shadow.brighter());
  77.     }
  78.  
  79.     public static Border createBevelBorder(int type,
  80.                         Color highlightOuter, Color highlightInner,
  81.                         Color shadowOuter, Color shadowInner) {
  82.         return new BevelBorder(type, highlightOuter, highlightInner, 
  83.                     shadowOuter, shadowInner);
  84.     }
  85.  
  86.     static Border createSharedBevel(int type)    {
  87.     if(type == BevelBorder.RAISED) {
  88.         return sharedRaisedBevel;
  89.     } else if(type == BevelBorder.LOWERED) {
  90.         return sharedLoweredBevel;
  91.     }
  92.     return null;
  93.     }
  94. //// EtchedBorder ///////////////////////////////////////////////////////////
  95.     static final Border sharedEtchedBorder = new EtchedBorder();
  96.  
  97.     public static Border createEtchedBorder()    {
  98.     return sharedEtchedBorder;
  99.     }
  100.  
  101.     public static Border createEtchedBorder(Color highlight, Color shadow)    {
  102.         return new EtchedBorder(highlight, shadow);
  103.     }
  104.  
  105. //// TitledBorder ////////////////////////////////////////////////////////////
  106.     public static TitledBorder createTitledBorder(String title)     {
  107.         return new TitledBorder(title);
  108.     }
  109.  
  110.     public static TitledBorder createTitledBorder(Border border)       {
  111.         return new TitledBorder(border);
  112.     }
  113.  
  114.     public static TitledBorder createTitledBorder(Border border, 
  115.                            String title) {
  116.         return new TitledBorder(border, title);
  117.     }
  118.  
  119.     public static TitledBorder createTitledBorder(Border border, 
  120.                         String title,
  121.                         int titleJustification,
  122.                         int titlePosition)      {
  123.         return new TitledBorder(border, title, titleJustification,
  124.                         titlePosition);
  125.     }
  126.  
  127.     public static TitledBorder createTitledBorder(Border border,           
  128.                         String title,
  129.                         int titleJustification,
  130.                         int titlePosition,
  131.                         Font titleFont) {
  132.         return new TitledBorder(border, title, titleJustification,
  133.                         titlePosition, titleFont);
  134.     }
  135.  
  136.     public static TitledBorder createTitledBorder(Border border,                     
  137.                         String title,
  138.                         int titleJustification,
  139.                         int titlePosition,
  140.                         Font titleFont,
  141.                         Color titleColor)       {
  142.         return new TitledBorder(border, title, titleJustification,
  143.                         titlePosition, titleFont, titleColor);
  144.     }
  145. //// EmptyBorder ///////////////////////////////////////////////////////////    
  146.     final static Border emptyBorder = new EmptyBorder(0, 0, 0, 0);
  147.  
  148.     public static Border createEmptyBorder() {
  149.     return emptyBorder;
  150.     }
  151.  
  152.     public static Border createEmptyBorder(int top, int left, 
  153.                         int bottom, int right) {
  154.     return new EmptyBorder(top, left, bottom, right);
  155.     }
  156.  
  157. //// CompoundBorder ////////////////////////////////////////////////////////
  158.     public static CompoundBorder createCompoundBorder() { 
  159.     return new CompoundBorder(); 
  160.     }
  161.  
  162.     public static CompoundBorder createCompoundBorder(Border outsideBorder, 
  163.                         Border insideBorder) { 
  164.     return new CompoundBorder(outsideBorder, insideBorder); 
  165.     }
  166.  
  167. //// MatteBorder ////////////////////////////////////////////////////////
  168.     public static MatteBorder createMatteBorder(int top, int left, int bottom, int right, 
  169.                                                 Color color) {
  170.         return new MatteBorder(top, left, bottom, right, color);
  171.     }
  172.  
  173.     public static MatteBorder createMatteBorder(int top, int left, int bottom, int right, 
  174.                                                 Icon tileIcon) {
  175.         return new MatteBorder(top, left, bottom, right, tileIcon);
  176.     }
  177. }
  178.